<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('主持人管理')"/>
</head>
<body class="gray-bg">

<h1>ORDER</h1>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            下单人姓名：<input type="text" name="orderCustomerName"/>
                        </li>
                        <li>
                            下单公司：<input type="text" name="cname"/>
                        </li>
                        <li>
                            主持人姓名：<input type="text" name="orderHostname"/>
                        </li>
                        <li>
                            下单时间：
                            <input type="text" class="time-input" style="width: 300px; display: inline;"  name="orderCreatetime"/>

                        </li>
                        <li>
                            全部状态：
                            <select name="orderState" th:with="type=${@dict.getType('sys_normal_disable')}">
                                <option value="-1">请选择</option>
                                <option value="0">未主持</option>
                                <option value="1">已主持</option>
                                <option value="2">已删除</option>
                            </select>
                        </li>

                        <li>
                            全部角色：
                            <select name="orderCustomertype" th:with="type=${@dict.getType('sys_normal_disable')}">
                                <option value="-1">请选择</option>
                                <option value="0">新人</option>
                                <option value="1">婚庆公司</option>
                            </select>
                        </li>
                        <li>
                            典礼时间：
                            <input type="text" class="time-input" style="width: 100px; display: inline;"  name="startOrderCeremonydate"/>
                            <span>-</span>
                            <input type="text" class="time-input" style="width: 100px; display: inline;"  name="stopOrderCeremonydate"/>

                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="members:order:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('members:order:edit')}]];
    var removeFlag = [[${@permission.hasPermi('members:order:remove')}]];
    var disableFlag = [[${@permission.hasPermi('members:order:state')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "members/order";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "orderId",
            modalName: "订单",
            sortOrder: "desc",
            showFooter: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderId',
                    title: '编号'
                },
                {

                    field: 'fileName',
                    title: '下单人<br>电话',
                    alert: 'center',
                    formatter: function (value, row, index) {
                        return row.orderCustomerName+"</br>"+row.orderPhone;
                    }
                },
                {
                    field: 'orderCustomertype',
                    title: '下单公司',
                    formatter: function (value, row, index) {
                        if (value == 0) {
                            return "新人";
                        }else if (value == 1) {
                            return row.companyName;
                        }
                    }
                },
                {
                    field: 'orderHostname',
                    title: '主持人'
                },
                {
                    field: 'orderHotel',
                    title: '酒店名称',
                    sortable: true
                },
                {
                    field: 'orderCreatetime',
                    title: '下单时间',
                    sortable: true
                },
                {
                    field: 'orderCeremonydate',
                    title: '典礼时间',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var date1 = eval('new Date(' + row.orderCeremonydate.replace(/\d+(?=-[^-]+$)/,
                            function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
                        var datetime = new Date();
                        datetime.setTime(date1);
                        var year = datetime.getFullYear();
                        var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
                        var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
                        var datetimevalue = null;

                        if(row.orderCeremonytime==0){
                            datetimevalue =  "全天"
                        }
                        if(row.orderCeremonytime==1){
                            datetimevalue =  "上午"
                        }
                        if(row.orderCeremonytime==2){
                            datetimevalue = "下午"
                        }

                        return year + "-" + month + "-" + date+'<br>'+datetimevalue
                    }
                },
                {
                    field: 'orderPrice',
                    title: '金额',
                    sortable: true,
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].orderPrice);
                        }
                        return  "总额度"+sumBalance+"元"
                    }
                },
                {
                    field: 'orderState',
                    title: '订单状态',
                    formatter: function (value, row, index) {
                        if (value == 0) {
                            return "<span style='color:#33cabb;'>未主持</span>";
                        }else if (value == 1){
                            return "<span style='color:greenyellow;'>已主持</span>";
                        }else if (value == 2){
                            return "<span style='color:red;'>已删除</span>";
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="permissionSet('+row.hostId+')">查看评价</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

    });


    function permissionSet(hostId) {
        $.modal.open("权限设置", "/user/host/permissionset/"+hostId);
    }

    // 修改状态，禁用和启用
    function updateState(obj, hostId, hostState) {
        if (hostState == 2) {
            hostState = 1;
        } else {
            hostState = 2;
        }
        $.post(prefix + "/updateState", {"hostId": hostId, "hostState": hostState}, function (data) {
            if (data.code == 0) {
                $.table.refresh();
            } else {
                $.modal.msgSuccess("操作失败");
            }
        }, "json");
    }

    var oldValue = 100;

    //权重获取焦点
    function sortWeightFocus(obj) {
        oldValue = $(obj).val();
    }

    //权重失去焦点
    function sortWeightblur(obj) {

        var weight = $(obj).val();
        if (isNaN(weight) == false) {
            var weightInt = parseInt(weight);
            if (weightInt == parseFloat(weight)) {
                if (weightInt >= 0 && weightInt <= 100) {

                    var hostId = $(obj).parent().prev().text();
                    $.post(prefix + "/update/sortweight", {
                        "hostSortWeight": weightInt,
                        "hostId": hostId
                    }, function (data) {
                        if (data.code == 0) {
                            $.table.refresh();
                        }
                    })
                } else {
                    $.modal.alertWarning("只支持0-100的整数");
                    $(obj).val(oldValue);
                }
            } else {
                $.modal.alertWarning("只支持整数");
                $(obj).val(oldValue);
            }
        } else {
            $.modal.alertWarning("请输入数字");
            $(obj).val(oldValue);
        }
    }

</script>
</body>
</html>